//
//  AppDelegate.m
//  必争医疗
//
//  Created by 8号球 on 14-11-19.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "AppDelegate.h"
#import "HospitalViewController.h"
#import "MineViewController.h"
#import "NewsViewController.h"
#import "SearchViewController.h"
#import "UserViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

//开始项目

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]autorelease];
    [_window makeKeyAndVisible];
    [self creatView];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeView :) name:@"HELP" object:nil];
    MineViewController *mine = [[[MineViewController alloc]init]autorelease];
    UINavigationController *mineN = [[UINavigationController alloc]initWithRootViewController:mine];
    UIImage *i1 = [UIImage imageNamed:@"1.png"];
    UIImage *im1 = [i1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *i1t = [UIImage imageNamed:@"1t.png"];
    UIImage *im1t = [i1t imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    mineN.tabBarItem = [[[UITabBarItem alloc]initWithTitle:@"我的医疗" image:im1 selectedImage:im1t]autorelease];
    SearchViewController *search = [[[SearchViewController alloc]init]autorelease];
    UINavigationController *searchN = [[[UINavigationController alloc]initWithRootViewController:search]autorelease];
    UIImage *i2 = [UIImage imageNamed:@"2.png"];
    UIImage *im2 = [i2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *i2t = [UIImage imageNamed:@"2t.png"];
    UIImage *im2t = [i2t imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    searchN.tabBarItem = [[[UITabBarItem alloc]initWithTitle:@"自查" image:im2 selectedImage:im2t]autorelease];
    HospitalViewController *hospital = [[[HospitalViewController alloc]init]autorelease];
    UINavigationController *hospitalN = [[[UINavigationController alloc]initWithRootViewController:hospital]autorelease];
    UIImage *i3 = [UIImage imageNamed:@"3.png"];
    UIImage *im3 = [i3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *i3t = [UIImage imageNamed:@"3t.png"];
    UIImage *im3t = [i3t imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    hospitalN.tabBarItem = [[[UITabBarItem alloc]initWithTitle:@"空中医院" image:im3 selectedImage:im3t]autorelease];
    NewsViewController *news = [[[NewsViewController alloc]init]autorelease];
    UINavigationController *newsN = [[[UINavigationController alloc]initWithRootViewController:news]autorelease];
    UIImage *i4 = [UIImage imageNamed:@"4.png"];
    UIImage *im4 = [i4 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *i4t = [UIImage imageNamed:@"4t.png"];
    UIImage *im4t = [i4t imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    newsN.tabBarItem = [[[UITabBarItem alloc]initWithTitle:@"新闻" image:im4 selectedImage:im4t]autorelease];
    UserViewController *user = [[[UserViewController alloc]init]autorelease];
    UINavigationController *userN = [[[UINavigationController alloc]initWithRootViewController:user]autorelease];
    UIImage *i5 = [UIImage imageNamed:@"5.png"];
    UIImage *im5 = [i5 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *i5t = [UIImage imageNamed:@"5t.png"];
    UIImage *im5t = [i5t imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    userN.tabBarItem = [[[UITabBarItem alloc]initWithTitle:@"我的帐号" image:im5 selectedImage:im5t]autorelease];
    NSArray *homeArray = [NSArray arrayWithObjects:mineN, searchN, hospitalN, newsN, userN, nil];
    UITabBarController *home = [[[UITabBarController alloc]init]autorelease];
    [home setViewControllers:homeArray animated:YES];
    home.selectedIndex = 2;
    [_window setRootViewController:home];
    
    return YES;
}
- (void)creatView
{
    UIView *v = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, 375, 667 - 20)]autorelease];
    UIScrollView *s = [[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 375, 667 - 20)]autorelease];
    v.alpha = 0.5;
    v.backgroundColor = [UIColor grayColor];
    v.tag = 1;
    s.tag = 2;
    s.contentSize = CGSizeMake(375 * 2, 0);
    [self.window addSubview:v];
    [self.window addSubview:s];
}
- (void)changeView :(NSNotification *)n
{
    [self.window bringSubviewToFront:[self.window viewWithTag:1]];
    [self.window bringSubviewToFront:[self.window viewWithTag:2]];
    NSDictionary *info = n.userInfo;
    [[self.window viewWithTag:2]addSubview:[info objectForKey:@"1"]];
    [[self.window viewWithTag:2]addSubview:[info objectForKey:@"2"]];
    [[self.window viewWithTag:2]addSubview:[info objectForKey:@"3"]];
    [[info objectForKey:@"3"]addTarget:self action:@selector(BA:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)BA :(id)sender
{
    [self.window sendSubviewToBack:[self.window viewWithTag:1]];
    [self.window sendSubviewToBack:[self.window viewWithTag:2]];
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
